package com.elaticsearch.test;

import com.sun.org.slf4j.internal.Logger;
import com.sun.org.slf4j.internal.LoggerFactory;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;

import java.io.IOException;

/**
 * @author:左泽林
 * @date:日期:2021-08-28-时间:10:38
 * @message:
 */

public class ESTest_Index_Create {
    private static final Logger logger = LoggerFactory.getLogger(ESTest_Index_Create.class);

    public static void main(String[] args) throws IOException {

        logger.error("========================创建索引====================");
        //创建ES客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("172.20.17.43",9200,"http"))
        );

        //创建索引a
        CreateIndexRequest request = new CreateIndexRequest("dcx");
        CreateIndexResponse createIndexResponse = esClient.indices().create(request, RequestOptions.DEFAULT);

        //响应状态
        boolean acknowledged = createIndexResponse.isAcknowledged();
        System.out.println("索引操作"+acknowledged);

        esClient.close();
    }
}
